using MicroMsg.Manager;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.UserContrl
{
	public class BrandCustomLinksCtrl : UserControl
	{
		private const string TAG = "BrandCustomLinksCtrl";
		private bool mBIsFirstLoaded = true;
		public static DependencyProperty ItemObjectProperty = DependencyProperty.Register("ItemObject", typeof(Contact), typeof(BrandCustomLinksCtrl), new PropertyMetadata(null, new PropertyChangedCallback(BrandCustomLinksCtrl.OnItemObjectPropertyChanged)));
		internal StackPanel LayoutRoot;
		private bool _contentLoaded;
		public Contact ItemObject
		{
			get
			{
				return (Contact)base.GetValue(BrandCustomLinksCtrl.ItemObjectProperty);
			}
			set
			{
				base.SetValue(BrandCustomLinksCtrl.ItemObjectProperty, value);
			}
		}
		public BrandCustomLinksCtrl()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.Control_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Control_Unloaded));
		}
		private void Control_Loaded(object sender, RoutedEventArgs e)
		{
		}
		private void Control_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		private static void OnItemObjectPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == BrandCustomLinksCtrl.ItemObjectProperty)
			{
				(dependencyObject_0 as BrandCustomLinksCtrl).ItemObjectPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void ItemObjectPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_OldValue() != dependencyPropertyChangedEventArgs_0.get_NewValue())
			{
				this.RefreshUI();
			}
		}
		private void RefreshUI()
		{
			if (this.ItemObject == null)
			{
				this.LayoutRoot.get_Children().Clear();
				return;
			}
			this.LayoutRoot.get_Children().Clear();
			ListBrandLinks brandCustomLinks = ContactMgr.GetBrandCustomLinks(this.ItemObject.strBrandInfo);
			if (brandCustomLinks != null && brandCustomLinks.urls != null && brandCustomLinks.urls.get_Count() != 0)
			{
				using (List<BranCustomLink>.Enumerator enumerator = brandCustomLinks.urls.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						BranCustomLink current = enumerator.get_Current();
						if (current != null)
						{
							Button button = new Button();
							button.set_Style((Style)Application.get_Current().get_Resources().get_Item("buttonStyleListItem"));
							button.SetValue(TiltEffect.IsTiltEnabledProperty, true);
							TextBlock textBlock = new TextBlock();
							textBlock.set_Foreground(MMTheme.GetInstance().COMMON_BRUSH);
							textBlock.set_FontSize(30.0);
							textBlock.set_Text(current.title);
							button.set_Content(textBlock);
							button.set_Tag(current.String_0);
							button.set_Margin(new Thickness(0.0, 0.0, 0.0, 25.0));
							button.add_Click(new RoutedEventHandler(this.btn_Click));
							this.LayoutRoot.get_Children().Add(button);
						}
					}
				}
				return;
			}
		}
		private void btn_Click(object sender, RoutedEventArgs e)
		{
			if (sender == null)
			{
				return;
			}
			Button button = sender as Button;
			if (button == null)
			{
				return;
			}
			string text = button.get_Tag() as string;
			if (text == null)
			{
				return;
			}
			ToolFunction.GotoWebLinkInWebView(text, GetA8KeyScene.MMGETA8KEY_SCENE_PROFILE);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Contact/ProfileInfo/BrandCustomLinksCtrl.xaml", 2));
			this.LayoutRoot = (StackPanel)base.FindName("LayoutRoot");
		}
	}
}
